<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/include/header.jsp"%>
<link rel="stylesheet" type="text/css" href="${ctx}/static/h-ui/css/H-ui.min.css" />
<script src="${ctx}/component/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<title>查询凭证管理列表</title>
</head>
<body>
		<div class="main_panel">
		<div class="ch_panel" id="queryDiv">
			<input type="hidden" data-qname="CSRFToken" id="CSRFToken" value="${csrfToken}" id="csrfToken" />
			<table class="c_table">
				<tr>
					<td>
						<button class="a_btn" id="addBtn">新增</button>
					</td>
					<td class="t_l" style="padding-left: 10px;">
						凭证日期：
						<input type="text" value="${startTime }" class="date_txt" style="width: 100px;" id="startTime" name="startTime" data-qname="startTime" onfocus="WdatePicker({startDate:'%y',dateFmt:'yyyy-MM-dd'})" readonly="readonly"/>
						至
						<input type="text" class="date_txt" style="width: 100px;" id="endTime" name="endTime" data-qname="endTime" onfocus="WdatePicker({startDate:'%y',dateFmt:'yyyy-MM-dd'})" readonly="readonly"/>
					</td>
					<td class="t_l">
						纳入结账：
						<select id="isNrjz" name="isNrjz" data-qname="isNrjz" class="input_txt" style="width: 150px;">
							<option value="">--请选择--</option>
							<option value="0">未结账</option>
							<option value="1">已结账</option>
						</select>
					</td>
					<td width="30%"></td>
					<td class="t_r">
						<input type="button" value="查询" id="searchBtn" class="c_btn" />
					</td>
				</tr>
			</table>
		</div>
		<table id="tbwrap" class="table table-border table-bordered table-bg m_t10 hovaertable"></table>
		<div class="page eui-pager-custom" id="j_pager"></div>
	</div>

	<script type="text/html" id="tb_template">
		<thead>
			<tr>
				<th>凭证日期</th>
				<th>凭证字号</th>

				<th>摘要</th>
				<th>科目</th>
				<th>借方金额(元)</th>
				<th>贷方金额(元)</th>

				<th>制单人</th>
				<th>审核人</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody data-type="body">
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i],classItem = (i%2!=0)?"tr_odd":"even";
					var index = i;
				!>
				
				<!for(var j=0,len2=item["pzcList"].length;j<len2;j++){
						var item2 = item["pzcList"][j];
						var jcount = j;
					!>
					<tr name="tr<!=index!>">
						<!if(jcount<1) { !>
							<td rowspan="<!=item["pzcList"].length!>"><!=item["pzDateStr"]!></td>
							<td rowspan="<!=item["pzcList"].length!>">
								<a onclick="goToPingZheng('<!=item['uuid']!>')" style="color: #6699FF;">
									<!=item["pzz"]!>-<!=item["pzhStr"]!>
								</a>
							</td>
						<!}!>

						<td><!=item2["zyJl"]!></td>
                        <td><!=item2["kmmc"]!></td>
                        <td><!=item2["jfje"]!></td>
                        <td><!=item2["dfje"]!></td>

						<!if(jcount<1) { !>
							<td rowspan="<!=item["pzcList"].length!>"><!=item["zdr"]!></td>
							<td rowspan="<!=item["pzcList"].length!>"><!=item["shenHeRen"]!></td>
							<td rowspan="<!=item["pzcList"].length!>">

								<!if(item["isNrjz"]=="1") { !>
									已结账
								<!}else{!>
									<a title="修改" data-value="<!=item["uuid"]!>" class="edit">修改</a><br>
									<a title="删除" data-value="<!=item["uuid"]!>" class="delete">删除</a>
								<!}!>

							</td>	
						<!}!>

		             </tr>
				<!}!>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="10" class="t_cc"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
	</script>



	<script type="text/javascript">
		var pingZhengDialog;
		$(function() {

			// 添加
			$("#addBtn").click(function() {
				parent.article_add ('添加凭证信息', '${ctx}/pingZheng/toAdd');
			});
			
			// 编辑
			$("#tbwrap").delegate(".edit", "click", function() {
				var uuid = $(this).data("value");
				parent.article_add ('修改凭证信息', '${ctx}/pingZheng/toEdit?uuid=' + uuid);
			});
			// 4、删除
			$("#tbwrap").delegate(".delete", "click", function() {
				var uuid = $(this).data("value");
				if (confirm('确定删除？')) {
					$.post("${ctx}/pingZheng/delete", { uuid : uuid, CSRFToken : $("#CSRFToken").val()}, function(result) {
						if ("succ" == result) {
							alert("操作成功");
							// 刷新列表页面
							search(); 
							// 关闭弹窗窗口
			    			parent.pingZhengDialog.close();
						} else if ("notThroughSecurityCheck" == result["isThroughSecurityCheck"]) { // 如果不通过安全检查
							var mess = result["mess"];
							$.post("${ctx}/common/notThroughSecurityCheck?ts=" + new Date().getTime(), mess, function(res) {
								alert(res);
							},"json");
	
						} else {
							alert(result);
						}
					}, "json");
				}
			
			});
			// 5、查询
			$("#searchBtn").click(function() {
				search();
			});
			
			// 页面加载完成调用查询分页
			search();
		});
		
		function goToPingZheng(uuid){
			parent.article_add ('查看凭证信息', '${ctx}/pingZheng/view?uuid=' + uuid);
		 }
	</script>

	<script type="text/javascript">
		function search() {
			seajs.use(["component/table"], function (uiTable) {
		        $.post("${ctx}/pingZheng/ajaxPage",
		        		{
		        		page:1,
		        		startTime:$("#startTime").val(),
		        		endTime:$("#endTime").val(),
		        		isNrjz:$("#isNrjz").val()
		        		},function (result) {
		        	
		        	// 系统有异常信息
		        	if (JSON.stringify(result).indexOf("系统出现异常")>=0) {
		        		alert(result);
		        		return;
		        	}
		        	
	            	var table = new uiTable({
	                	"con": "#tbwrap",
	                    "data": {
	                         "list": result.dataList
	                    },
	                    "template": "tb_template",
	                    "pager": {
	                    	"con": "#j_pager",
	                        "data": {
	                        	"currentPage": result.currentPage,
	                            "pageCount": result.pageCount,
	                            "rowCount": result.rowCount
	                        },
	                        template: '<a title="首页" class="page_first" data-role="first" href="#"></a><a title="上一页" class="page_prev" href="#" data-role="prev"></a><div data-value="pageNum"></div><a title="下一页" class="page_next" href="#" data-role="next"></a><a title="尾页" class="page_last" href="#" data-role="last"></a> 共<span data-target="rowCount"></span>条   共<span data-target="pageCount"></span>页 跳转到 <input type="text" data-target="input" class="page_input"/><a href="#" data-role="go" class="go">GO</a>'
	                    }
	                });
	            	
	            	$(".hovaertable tr").hover(
       				  function () {
       				    var name = $(this).attr("name");
       				 	$(".hovaertable tr[name='"+name+"']").attr("style","background:#F2F4F7");
       				  },
       				  function () {
       					 var name = $(this).attr("name");
       					$(".hovaertable tr[name='"+name+"']").attr("style","");
       				  }
       				);
	            	
	                table.getPager().bind("changePage", function (event, page, hander) {
	                	$.post("${ctx}/pingZheng/ajaxPage",
	                			{
	                				page:page,
	        		        		startTime:$("#startTime").val(),
	        		        		endTime:$("#endTime").val(),
	        		        		isNrjz:$("#isNrjz").val()
	                			} ,function (result) {
		                    	if (JSON.stringify(result).indexOf("系统出现异常")>=0) {
					        		alert(result);
					        		return;
					        	}
		                    	
		                    	table.render({ "list": result.dataList});
			                    hander({"currentPage": result.currentPage, "pageCount": result.pageCount, "rowCount": result.rowCount });
			                    
			                    $(".hovaertable tr").hover(
	             				  function () {
	             				    var name = $(this).attr("name");
	             				 	$(".hovaertable tr[name='"+name+"']").attr("style","background:#F2F4F7");
	             				  },
	             				  function () {
	             					 var name = $(this).attr("name");
	             					$(".hovaertable tr[name='"+name+"']").attr("style","");
	             				  }
	             				);
		                 	}, 
		                "json");
	                });
	                
	        	}, "json");
	      	});
		}
	</script>
</body>
</html>
